package com.lishao.soccer.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.lishao.soccer.bean.entity.TmTeamOpponent;
import com.lishao.soccer.service.TmTeamOpponentService;
import com.lishao.system.security.providers.SecurityUser;
import com.lishao.system.utils.ActionUtil;
import com.opensymphony.xwork2.ActionSupport;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

public class TmTeamOpponentAction extends ActionSupport {
	TmTeamOpponentService tmTeamOpponentService;
	String jsonStr;
	Long teamOpponentId;
	
	public String findTeamOpponent() throws Exception{
		TmTeamOpponent tmTeamOpponent = tmTeamOpponentService.findTeamOpponent(teamOpponentId);
		Map resMap = new HashMap();
		resMap.put("tmTeamOpponent", tmTeamOpponent);
		new ActionUtil().writeMap(resMap);
		return null;
	}
	
	public String saveTeamOpponent() throws Exception{
		String strMessage = "";
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		TmTeamOpponent tmTeamOpponent = (TmTeamOpponent)JSONObject.toBean(JSONObject.fromObject(jsonStr, new JsonConfig()), TmTeamOpponent.class);
		tmTeamOpponent = tmTeamOpponentService.saveTeamOpponent(tmTeamOpponent, secUser.getSmUser());
		Map resMap = new HashMap();
		resMap.put("tmTeamOpponent", tmTeamOpponent);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}

	//get set
	public TmTeamOpponentService getTmTeamOpponentService() {
		return tmTeamOpponentService;
	}

	public void setTmTeamOpponentService(TmTeamOpponentService tmTeamOpponentService) {
		this.tmTeamOpponentService = tmTeamOpponentService;
	}

	public String getJsonStr() {
		return jsonStr;
	}

	public void setJsonStr(String jsonStr) {
		this.jsonStr = jsonStr;
	}

	public Long getTeamOpponentId() {
		return teamOpponentId;
	}

	public void setTeamOpponentId(Long teamOpponentId) {
		this.teamOpponentId = teamOpponentId;
	}
	
}
